package com.zzedu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzedu.domain.ZzClassesSendStudent;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * 班级课程解锁记录Mapper接口
 *
 * @author Mr.Wang
 * @date 2025-08-30
 */
public interface ZzClassesSendStudentMapper extends BaseMapper<ZzClassesSendStudent> {

    /**
     * 派发作业-列表
     *
     * @param page
     * @param classId
     * @param bookId
     * @return
     */
    @Select({
            "<script>",
            "SELECT a.stu_id as stuId, b.nick_name as nickName, b.stu_name stuName, b.avatar,b.valid_to expireAt, c.id id",
            "FROM zz_stu_classes_r a",
            "LEFT JOIN zz_student b ON a.stu_id = b.id",
            "LEFT JOIN zz_classes_send_student c ON c.stu_id = a.stu_id AND c.deleted = 0 AND c.book_id = #{bookId}",
            "WHERE a.deleted = 0",
            "  AND b.deleted = 0",
            "  AND a.class_id = #{classId}",
            "</script>"
    })
    IPage<Map<String, Object>> queryStudentsByClassIdAndBookId(
            @Param("page") IPage page,
            @Param("classId") Long classId,
            @Param("bookId") Long bookId
    );
}
